<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('设备库存')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <!--<div class="btn-group-sm" id="toolbar" role="group">-->
            <!--<a class="btn btn-warning" id="popupBatteryAll" shiro:hasPermission="system:device:popupBatteryAll">-->
                <!--弹出全部-->
            <!--</a>-->
        <!--</div>-->
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<input type="hidden" th:value="${deviceId}" id="deviceId"/>

<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var prefix = ctx + "system/device";
    var datas = [[${@dict.getType('sys_normal_disable')}]];

    var popupFlag = [[${@permission.hasPermi('system:device:popupBattery')}]];


    $(function () {
        var options = {
            url: prefix + "/listStock",
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            queryParams: {
                "id": $("#deviceId").val()
            },
            columns: [{
                radio: true
            },
                {
                    field: 'slot',
                    title: '卡槽位'
                },
                {
                    field: 'batterySn',
                    title: '电池SN'
                },
                {
                    field: 'lever',
                    title: '电池电量'
                },
                {
                    field: 'stockTime',
                    title: '库存时间'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-warning btn-xs ' + popupFlag + '" href="javascript:void(0)" onclick="popupBattery(\'' + row.slot + '\')" ">强弹</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });


    function popupBattery(slot) {
        var url = prefix + "/popupBattery";
        var deviceId = $("#deviceId").val();
        var data = {
            "slot": slot,
            "deviceId": deviceId
        };
        $.modal.confirm("确认弹出此电池？", function () {
            $.operate.submit(url, "post", "json", data);
        });
    }

    $("#popupBatteryAll").click(function () {
        var url = prefix + "/popupBattery";
        var deviceId = $("#deviceId").val();
        var data = {
            "slot": 255,
            "deviceId": deviceId
        };
        $.modal.confirm("确认弹出全部电池？", function () {
            $.operate.submit(url, "post", "json", data);
        });
    });

</script>
</body>
</html>